#include <gtk/gtk.h>
#include <gdk/gdk.h>
int main (int argc, char *argv[])
{
    GtkWidget *win = NULL;
    GtkWidget *vbox = NULL;
    GtkWidget *image;
    GdkPixbuf *pixbuf;


    //Initialize GTK+
    gtk_init (&argc, &argv);

    //Create the main window
    win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width (GTK_CONTAINER (win), 0);
    gtk_widget_set_usize(win, 193, 63);
    gtk_window_set_title (GTK_WINDOW (win), "Test draw rectangle to pixbuf");
    gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
    g_signal_connect (win, "destroy", gtk_main_quit, NULL);

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add (GTK_CONTAINER (win), vbox);

    //create pixbuf from image file
    pixbuf = gdk_pixbuf_new_from_file ("bg3.jpg", NULL);

    //get pixmap from pixbuf
    GdkPixmap *pixmap = NULL; 
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0);

    gint w =  gdk_pixbuf_get_width(pixbuf);
    gint h =  gdk_pixbuf_get_height(pixbuf);

    cairo_t *cr = gdk_cairo_create(pixmap);
    cairo_move_to(cr, 20, 20);   
    cairo_set_font_size(cr, 14);
    cairo_select_font_face(cr,"DongWen--Song", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);       
    cairo_show_text(cr, "aaa");
 
    pixbuf =  gdk_pixbuf_get_from_drawable(pixbuf, pixmap, NULL, 0, 0, 0, 0,  w, h);

    //create image widget from new pixbuf
    image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, TRUE, 0);
 
    //release
    g_object_unref(pixbuf);
    g_object_unref(pixmap);
 
    //show
    gtk_widget_show_all (win);

    gtk_main ();

    return 0;
}
